package com.liu.hooks;

import java.io.File;

import com.liu.util.TrackerLoger;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;

public class SharedPreferenceHook extends AbstractHook{

	public static final String TAG = "#SharedPreferenceHook#";
	
	public static final String TYPE = "com.liu.hooks.SharedPreferenceHook";
	
	XC_MethodHook sharedPreferenceHook = new XC_MethodHook() {
		
		@Override
		protected void afterHookedMethod(MethodHookParam param) throws Throwable {
			
			File file = (File) XposedHelpers.getObjectField(param.thisObject, "mFile");
			int mode = (Integer) XposedHelpers.getObjectField(param.thisObject, "mMode");
			
			synchronized (this) {
					TrackerLoger.log(TAG, "[Path] " + file.getAbsolutePath(), TYPE, true);
					TrackerLoger.log(TAG, "[Mode] " + mode, TYPE, true);
				}
			}
	};
	
	@Override
	public void doHook() {
		
		Class<?> sharedPreferenceImplClass = XposedHelpers.findClass("android.app.SharedPreferencesImpl", classloader);
		XposedBridge.hookAllConstructors(sharedPreferenceImplClass, sharedPreferenceHook);

	}

	@Override
	public void setClassLoader(ClassLoader classloader) {
		this.classloader = classloader;
	}
	
	

}
